package friend.content;


import common.totalInfo.*;
import java.util.*;
import last.tomsquare.*;
import android.app.*;
import android.content.*;
import android.os.Bundle;
import android.view.*;
import android.view.ViewGroup.LayoutParams;
import android.widget.*;

public class Friends extends Activity
{

	TextView loginUser, userPlace, userDate;
	View mPage2,fPhoto;
	ArrayList<MyList> arrItem;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.friends);
	   
	    
	    fPhoto = (View)findViewById(R.id.photo);
	    loginUser = (TextView)findViewById(R.id.user);
	    userPlace = (TextView)findViewById(R.id.lastplace);
	    userDate = (TextView)findViewById(R.id.lastdate);
	    mPage2 = (View)findViewById(R.id.title);
	 	    
	    arrItem = new ArrayList<MyList>();
		MyList ml;
		ml = new MyList(R.drawable.icon, "김태희","bangate@nate.com");arrItem.add(ml);
		ml = new MyList(R.drawable.icon, "전지현", "aaa@hanmail.net");arrItem.add(ml);
		ml = new MyList(R.drawable.icon, "최두성", "당구짱");arrItem.add(ml);
		ml = new MyList(R.drawable.icon, "최두성", "당구짱");arrItem.add(ml);

		MyInfoAdapter MyInfoAdapter = new MyInfoAdapter(this, R.layout.friendlist, arrItem);

		ListView list;
		list =(ListView)findViewById(R.id.myfriends);
		list.setAdapter(MyInfoAdapter);
	    
		
	 
	    list.setOnItemClickListener(new AdapterView.OnItemClickListener() 
	    {
	    	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	    	{
	    		if(position == 0)
	    		{
	    			Intent it = new Intent(Friends.this, FriendsInfo.class);
	    			startActivity(it);
	    		}
	    	}
	    });
	
	}
	
	
	
	
	 
	 public boolean onCreateOptionsMenu(Menu menu)
	 {
		 super.onCreateOptionsMenu(menu);
		 MenuItem item = menu.add(0,1,0,"친구추가");
		 item.setIcon(R.drawable.icon);
		 
		 return true;
	 }
	 
	 public boolean onOptionsItemSelected(MenuItem item)
	 {
		 	 
		 switch (item.getItemId())
		 {
		 case 1:
			 Intent intent1 = new Intent(this, FriendSearch.class);
			 startActivity(intent1);
			 break;
		 }
		 return false;
	 }
}





//리스트 뷰에 출력할 항목
class MyList 
{
	MyList(int abIcon, String abName, String abemail) 
	{
		aaIcon = abIcon;
		aaName = abName;
		aae_mail = abemail;
	}
	int aaIcon;
	String aaName;
	String aae_mail;
}

//어댑터 클래스
class MyInfoAdapter extends BaseAdapter 
{
	Context maincon1;
	LayoutInflater Inflater;
	ArrayList<MyList> arrSrc;
	int layout;

	public MyInfoAdapter(Context context, int alayout, ArrayList<MyList> aarSrc)
	{
		maincon1 = context;
		Inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
		arrSrc = aarSrc;
		layout = alayout;
	}

	public int getCount() 
	{
		return arrSrc.size();
	}

	public String getItem(int position)
	{
		return arrSrc.get(position).aaName;
	}

	public long getItemId(int position) 
	{
		return position;
	}

	// 각 항목의 뷰 생성
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		final int pos = position;
		if (convertView == null) 
		{
			convertView = Inflater.inflate(layout, parent, false);
		}
		ImageView img = (ImageView)convertView.findViewById(R.id.img1);
		img.setImageResource(arrSrc.get(position).aaIcon);

		TextView txt4 = (TextView)convertView.findViewById(R.id.textfriend);
		txt4.setText(arrSrc.get(position).aaName);
		TextView txt5 = (TextView)convertView.findViewById(R.id.textfriend2);
		txt5.setText(arrSrc.get(position).aae_mail);
		Button btn = (Button)convertView.findViewById(R.id.btn12);
		btn.setOnClickListener(new Button.OnClickListener() 
		{
			public void onClick(View v) {
				String str = arrSrc.get(pos).aaName + "님 내꺼로 등록";
				Toast.makeText(maincon1, str, Toast.LENGTH_SHORT).show();
			}
		});

		return convertView;
	}
}
